﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xycn.IAuthorize;

namespace xycn.pluginsupport.BaseHelperPlugins
{

    /// <summary>
    /// 权限辅助类
    /// </summary>
    public static class AuthHelper
    {
        public static IAuthorize.IAuthorize authHelper = null;

        /// <summary>
        /// 添加权限插件接口
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbfactory"></param>
        /// <returns></returns>
        public static int Init(IPluginFactory.IPluginFactory logfactory)
        {
            if (logfactory == null)
                return -1;

            authHelper = (IAuthorize.IAuthorize)logfactory.CreatePlugin();
            return 0;
        }

        /// <summary>
        /// 获取认证信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static SignInfo GetSignInfo(string token)
        {            
            return authHelper.GetSignInfo(token);
        }

        /// <summary>
        /// 验证签名是否正确
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static bool IsSuccess(string token)
        {           
            return authHelper.IsSuccess(token);
        }

        /// <summary>
        /// 获取签名信息 Authorization 授权后访问需带上 Authorization：Bearer {Token}
        /// </summary>
        /// <param name="authInfo"></param>
        /// <returns></returns>
        public static string CreateSign(SignInfo authInfo)
        {
            return authHelper.CreateSign(authInfo);
        }
    }
}
